package com.atguigu.lease.web.admin.controller.attr;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.FacilityInfoTypeEnum;
import com.atguigu.lease.web.admin.service.FacilityInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/facility")
@Tag(name = "配套信息管理模块")
public class FacilityInfoController {
    /*
        当提交的参数类型固定 有映射的含义时，可以使用枚举类来存储映射数据
            1、springmvc接收到参数 转为 接口的实参传入时
                它会将接收的参数转为接口要求的类型传入
                springmvc有默认的转换器converter，可以将默认的字符串类型的参数转为接口要求的类型
            2、解决：
                编写将字符串转为枚举对象的转换器
     */
    @Resource
    FacilityInfoService facilityInfoService;
//    @Operation(summary = "根据type查询配套信息列表： 1-公寓 2-房间")
//    @GetMapping("/list")
//    public Result<List<FacilityInfo>> listByType(@RequestParam(required = false) Integer type){
//        return Result.ok(facilityInfoService.listByType(type));
//    }
    //使用枚举类接收type
    @Operation(summary = "根据type查询配套信息列表： 1-公寓 2-房间")
    @GetMapping("/list")
    public Result<List<FacilityInfo>> listByType(@RequestParam(required = false,value = "type")
                                                     FacilityInfoTypeEnum typeEnum){
        return Result.ok(facilityInfoService.listByType(typeEnum));
    }

    @Operation(summary = "新增或更新 配套信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo){
        return Result.build(facilityInfoService.saveOrUpdateFacilityInfo(facilityInfo));
    }
    @Operation(summary = "删除配套信息")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam("id")Long id){
        return Result.build(facilityInfoService.removeById(id));
    }
}
